<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category SystemService.php
 * @Depiction
 * @Author hwy
 * @Date 2021/4/22  15:22
 * +--------------------------------------------------------+
 */

namespace App\Services;

use Illuminate\Support\Facades\Redis;

class SystemService extends BaseService
{
    /**
     * @param $cache_name_log
     * @param $model
     * @return bool
     * @Depiction redis队列数据写入数据库 统一方法
     * @Author hwy
     * @Date 2021/4/28  11:22
     */
    public function redisInsert($cache_name_log, $model)
    {
        $log_len     = Redis::llen($cache_name_log);
        $insert_data = [];
        $i           = 1;
        while ($i <= $log_len) {
            $insert_data[] = json_decode(Redis::lPop($cache_name_log), true);
            if (!empty($insert_data)) {
                if ($i % 300 == 0) {
                    $model->insert($insert_data);
                    $insert_data = [];
                }
            }
            $i++;
        }
        $model->insert($insert_data);

        return $log_len;
    }

}